<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>求和</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <div>
      <div style="display: inline-block" v-for="(item,index) in arr" :key="index">
        <input v-model="isChecked" type="checkbox" :value="item" />
        <span>{{item}}</span>
      </div>
      <p>你选中的元素, 累加的值和为: {{total}}</p>
    </div>
  </div>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        isChecked: [],
        arr: [9, 15, 19, 25, 29, 31, 48, 57, 62, 79, 87],
      },
      methods: {

      },
      computed: {
        //   total() {
        //     return this.arr.reduce((prev, item) => this.isChecked ? prev + item : prev, 0)
        //   }
        total() {
          console.log(this.isChecked);
          return this.isChecked.reduce((prev, item) => prev + item, 0)
        }
      },
      watch: {
      }
    })
  </script>
</body>

</html>